package com.ruoyi.project.system.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.service.IPerQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 病人问卷答案Controller
 */
@RestController
@RequestMapping("/api/perQuery")
public class PerQueryController extends BaseController {

    @Autowired
    private IPerQueryService perQueryService;

    /**
     * 根据resId获取病人问卷答案列表
     * @param resId 病人唯一标识（必填）
     * @return 按顺序排列的非空答案数组
     */
    @GetMapping("/answers")
    public AjaxResult getAnswersByResId(@RequestParam(required = true) String resId) {
        try {
            // 参数非空校验
            if (resId == null || resId.trim().isEmpty()) {
                return AjaxResult.error("resId不能为空");
            }

            List<String> answers = perQueryService.selectAnswersByResId(resId.trim());
            return AjaxResult.success(answers);
        } catch (Exception e) {
            logger.error("获取病人问卷答案失败：", e);
            return AjaxResult.error("获取病人问卷答案失败，请联系管理员");
        }
    }
}